<template>
  <layout>
   
    <div>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span style="font-size: 20px;">创建证书列表</span>

        </div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="序号" prop="id">
            <el-input v-model="ruleForm.id" placeholder="请选择输入序号"></el-input>
          </el-form-item>
          <el-form-item label="标准编号" prop="pid">
            <el-input v-model="ruleForm.pid" placeholder="请选择输入标准编号"></el-input>
          </el-form-item>
          <el-form-item label="标准名称" prop="name">
            <el-input v-model="ruleForm.name" placeholder="请选择输入标准名称"></el-input>
          </el-form-item>
          <el-form-item label="发布日期">
            <el-col :span="11">
              <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1"
                style="width: 100%;"></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="实施日期">
            <el-col :span="11">
              <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date2"
                style="width: 100%;"></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </layout>
</template>

<script>
import Layout from "@/components/Layout.vue"
import axios from "axios";
export default {
  data() {
    return {
      ruleForm: {
        pid: '',
        id: '',
        name: '',
        date1: '',
        date2: '',
      },
      rules: {
        id: [{ required: true, message: '请输入序号', trigger: 'blur' }],
        pid: [
          { required: true, message: '请输入标准编号', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入标准名称', trigger: 'blur' }
        ]
      }
    }
  },
  components: {
    Layout
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios({
            url: "http://43.143.166.235:8090/chaxun/add",
            method: "post",
            data: {
              "id": this.ruleForm.id,
              "pid": this.ruleForm.pid,
              "name": this.ruleForm.name,
              "add_time": this.ruleForm.add_time,
              "update_time": this.ruleForm.update_time
            }
          }).then(res => {
            console.log(res)
            this.$router.push({
              name: 'booklist'
            })
          })
          console.log(this.ruleForm)
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}

</script>